package demo5;


import java.util.Arrays;

class Student implements Comparable<Student>{
    private int age;
    private String name;
    private double score;

    public Student(int age, String name, double score) {
        this.age = age;
        this.name = name;
        this.score = score;
    }

    @Override
    public String toString() {
        return "Student{" +
                "age=" + age +
                ", name='" + name + '\'' +
                ", score=" + score +
                '}';
    }


    public int compareTo(Student o) {
        return this.age-o.age;//以年龄进行比较
    }


}
public class Test {
    public static void main(String[] args) {
        Student student=new Student(18,"wzj",99.9);
        Student student1=new Student(14,"wj",12.9);
        Student student2=new Student(11,"wzj1",23.9);
        Student[]arr=new Student[]{student,student1,student2};
        System.out.println(Arrays.toString(arr));
        Arrays.sort(arr);
        System.out.println(Arrays.toString(arr));

    }
}
